package testcase.doctor;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.doctor.UserCase;
import common.Host;
import common.TestData;

/**
 * 帮忙医医生端获取用户报告UserCase接口测试用例
 * @author lipeng
 *
 */
public class TestUserCase {
	/**
	 * 帮忙医医生端获取用户报告UserCase接口测试数据驱动
	 * @return  测试数据
	 * @throws Exception
	 */
    @DataProvider (name = "Test_Report")
    public static String[][] testUserCaseDataProvider_Report() throws Exception{
    	Host.setup("Test");
    	TestData td = new TestData("doctor/TestUserCase.xml");
    	return td.getParam("Report");
    }
    
    /**
     * 帮忙医医生端查看历史UserCase接口测试数据驱动
     * @return  测试数据
     * @throws Exception
     */
    @DataProvider(name="Test_HistoricalRecord")
    public static String[][] testUserCaseDataProvider_HistoricalRecord() throws Exception{
    	Host.setup("Test");
    	TestData td = new TestData("doctor/TestUserCase.xml");
    	return td.getParam("HistoricalRecord");
    }
  
    /**
     * 帮忙医医生端保存记录UserCase接口测试数据驱动
     * @return   测试数据
     * @throws Exception
     */
    @DataProvider(name="Test_SaveRecord")
    public static String[][] testUserCaseDataProvider_SaveRecord() throws Exception{
    	Host.setup("Test");
    	TestData td = new TestData("doctor/TestUserCase.xml");
    	return td.getParam("SaveRecord");
    }
    
    /**
     * 帮忙医医生端获取完整报告UserCase接口测试数据驱动
     * @return   测试数据
     * @throws Exception
     */
    @DataProvider(name="Test_GetReport")
    public static String[][] testUserCaseDataProvider_GetReport() throws Exception{
        Host.setup("Test");
        TestData td = new TestData("doctor/TestUserCase.xml");
        return td.getParam("GetReport");
    }
    
    /**
     * 帮忙医医生端获取用户报告接口UserCase测试环境数据驱动
     * @return 测试数据
     * @throws Exception
     */
    @DataProvider(name="Test_GetCase")
    public static String[][] testUserCaseDataProvider_GetCase() throws Exception
    {
    	Host.setup("Test");
        TestData td = new TestData("doctor/TestUserCase.xml");
        return td.getParam("GetCase");
    }
    
    /**
     * 帮忙医医生端获取用户报告UserCase接口测试用例
     * @param casename  --用例名称
     * @param token     --token
     * @param subjectId  --subjectID
     * @throws Exception
     */
    @Test(dataProvider="Test_Report",groups={"Test"})
    public void testUserCaseTestCase(String casename,String token,String subjectId)throws Exception{
    	String result = UserCase.get(token,subjectId);
    	JSONObject jsonResult;
    	if(result == null || result.isEmpty()){
    		jsonResult = null;
    	}else {
			jsonResult = new JSONObject(result);
		}
    	
    	//设置检查点
    	switch (casename) {
		case "GetUserReport":
			   Assert.assertEquals(jsonResult.getJSONObject("Data").getString("UserID").isEmpty(), false);
			break;
		case "NOSubjectID":
			   Assert.assertEquals(jsonResult.getJSONObject("Data").getString("UserID"),"0");
			break;
		default:
			break;
		}
    }
    
    @Test(dataProvider="Test_HistoricalRecord",groups="Test")
    public void testUserCaseTestCase(String casename,String token,String userId,String flag)throws Exception{
    	String result = UserCase.get(token, userId, flag);
    	JSONObject jsonResult;
    	if(result == null || result.isEmpty()){
    		jsonResult=null;
    	}else {
			jsonResult = new JSONObject(result);
		}
    	
    	//设置检查点
    	switch (casename) {
		case "ViewHistory":
			 Assert.assertEquals(jsonResult.getJSONObject("Data").getJSONArray("userCaseList").getJSONObject(0).getString("CreateUserID").isEmpty(),false);
			break;
		case "NoUserID":
			 Assert.assertNull(jsonResult);
			break;

		default:
			break;
		}
    }
    
    @Test(dataProvider="Test_SaveRecord",groups="Test")
    public void testUserCaseTestCase(String casename,String token,String SubjectID,String UserID,String ChiefComplaint,String CaseHistory,String MianDesc,String Judgement,String Suggestion,String ID)throws Exception{
    	String result = UserCase.put(token, SubjectID, UserID, ChiefComplaint, CaseHistory, MianDesc, Judgement, Suggestion, ID);
    	JSONObject jsonResult;
    	if(result==null || result.isEmpty()){
    		jsonResult = null;
    	}else {
			jsonResult = new JSONObject(result);
		}
    	
    	//设置检查点
    	switch (casename) {
		case "SaRecord":
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(),false);
			break;
		case "NoChiefComplaint":
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(),false);
			break;
		case "NoCaseHistory":
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(),false);
			break;
		case "NoMainDesc":
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(),false);
			break;
		case "NoJudgement":
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(),false);
			break;
		case "NoSuggestion":
			Assert.assertEquals(jsonResult.getString("Data").isEmpty(),false);
			break;
		default:
			break;
		}
    }
    
    @Test(dataProvider="Test_GetReport",groups="Test")
    public void testUserCaseTestCase(String casename,String token,String studyid,String isAllReport,String rType)throws Exception{
    	String result = UserCase.get(token, studyid, isAllReport, rType);
    	JSONObject jsonResult;
    	if(result==null || result.isEmpty()){
    		jsonResult = null;
    	}else{
    		jsonResult = new JSONObject(result);
    	}
    	
    	//设置检查点
    	switch (casename) {
		case "GetRe":
			Assert.assertEquals(jsonResult.getJSONObject("Data").getString("Studyid").isEmpty(), false);
			break;

		default:
			break;
		}
    }
    
    /**
     * 帮忙医医生端获取用户报告接口UserCase测试环境测试用例
     * @param caseName 用例名
     * @param SubjectID 会话ID
     * @param rType 类型
     * @param source 资源
     * @param userId 用户ID
     * @param token 调接口需要的token
     * @throws IOException
     * @throws JSONException 
     */
    @Test(dataProvider="Test_GetCase",groups="Test")
    public void testUserCaseTestCase_GetCase(String caseName,String SubjectID,String rType,String source,String userId,String token) throws IOException, JSONException
    {
    	String result=UserCase.get(SubjectID, rType, source, userId, token);
    	switch (caseName)
		{
			case "Success":
				Assert.assertNotNull(result);
				break;
			case "SubjectIDWrong":
				Assert.assertNotNull(result);
				break;
			case "SubjectIDNull":
				Assert.assertNotNull(result);
				break;
			case "UserIdWrong":
				Assert.assertNotNull(result);
				break;
			case "UserIdNull":
				Assert.assertNull(result);
				break;
			case "TokenWrong":
				Assert.assertNotNull(result);
				break;
			case "TokenNull":
				Assert.assertNotNull(result);
				break;
			default:
				break;
		}
    }
}
